﻿<visi:VisiPage x:Class="VNet.VisiSuite.VisiBoard.Views.ConfigurationView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:visi="clr-namespace:VNet.VisiSuite.VisiBoard.Controls"
        xmlns:vuc="clr-namespace:VNet.VisiSuite.Controls;assembly=VNet.VisiSuite.Controls" mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800" Loaded="VisiPage_Loaded"
        xmlns:vm="clr-namespace:VNet.VisiSuite.VisiBoard.ViewModels"
        DataContext="{DynamicResource ConfigurationViewModel}"       
        xmlns:converter="clr-namespace:VNet.VisiSuite.Common.Converters;assembly=VNet.VisiSuite.Common"
        xmlns:c="clr-namespace:VNet.VisiSuite.VisiBoard.Controls"
        xmlns:helper="clr-namespace:VNet.VisiSuite.VisiBoard.Common.Helpers">
    <visi:VisiPage.Resources>
        <vm:ConfigurationViewModel x:Key="ConfigurationViewModel" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <converter:InvertBooleanConverter x:Key="InvertBooleanConverter" />
        <converter:InvertBooleanVisibilityConverter x:Key="InvertBooleanVisibilityConverter" />

        <Style x:Key="ConfigurationTextBlockStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource NormalTextBlockStyle}">
            <Setter Property="FontFamily" Value="{StaticResource AppFontFamily}" />
            <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}" />
            <Setter Property="FontSize" Value="14.667" />
            <Setter Property="Focusable" Value="False" />
            <Setter Property="Margin" Value="0,10,0,0" />
        </Style>

        <Style x:Key="ConfigurationTextBoxStyle" TargetType="TextBox" BasedOn="{StaticResource NormalTextBoxStyle}">
            <Setter Property="FontSize" Value="14.667" />
        </Style>

        <Style x:Key="ConfigurationPasswordBoxStyle" TargetType="PasswordBox" BasedOn="{StaticResource NormalPasswordBoxStyle}">
            <Setter Property="FontSize" Value="14.667" />
        </Style>

        <Style x:Key="ConfigurationButtonStyle" TargetType="Button" BasedOn="{StaticResource ButtonStyle}">
            <Setter Property="FontSize" Value="14.667" />
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="Margin" Value="0 24 0 0" />
        </Style>
    </visi:VisiPage.Resources>
    <vuc:BusyIndicator IsBusy="{Binding IsBusy}">
        <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{StaticResource WhiteColor}" Focusable="False">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="42" />
            </Grid.RowDefinitions>

            <!--Header-->
            <c:Header1Control Grid.Row="0" Title="{Binding PageTitle}" MenuIcons="{Binding TopRightButtonIcons}" />

            <!--Body-->
            <Grid Grid.Row="1">

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock Style="{StaticResource CaptionTextBlockStyle}" Grid.Row="0" Margin="105,25,15,0" Text="Enter your password to gain access to the VisiBoard" />

                <TextBlock Grid.Row="1" Style="{StaticResource ConfigurationTextBlockStyle}" Text="{Binding StatusMessage, Mode=OneWay}" HorizontalAlignment="Center"
                        Visibility="{Binding CellExisted,Converter={StaticResource BooleanToVisibilityConverter},ConverterParameter=Collapsed}" />

                <Grid Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding CellExisted,Converter={StaticResource InvertBooleanVisibilityConverter}}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Row="2" Style="{StaticResource ConfigurationTextBlockStyle}" Text="Password" />
                    <PasswordBox x:Name="_passwordTxt" Grid.Row="3" Style="{StaticResource ConfigurationPasswordBoxStyle}" helper:PasswordHelper.BindPassword="true"
                            vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}"
                            helper:PasswordHelper.BoundPassword="{Binding Model.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors= True,NotifyOnValidationError=True}"
                            KeyDown="OnEnterKeyDown" />

                    <TextBlock Grid.Row="4" Style="{StaticResource ConfigurationTextBlockStyle}" Text="Install Key" Visibility="{Binding Visibility}" />
                    <TextBox Grid.Row="5" Style="{StaticResource ConfigurationTextBoxStyle}" vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}"
                            Text="{Binding Model.InstallKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" KeyDown="OnEnterKeyDown"
                            Visibility="{Binding Visibility}" />

                    <TextBlock Grid.Row="6" Style="{StaticResource ConfigurationTextBlockStyle}" Text="Service URL" Visibility="{Binding Visibility}" />
                    <TextBox Grid.Row="7" Style="{StaticResource ConfigurationTextBoxStyle}" vuc:ValidationSummaryValidator.AdornerSite="{Binding ElementName=validationSummary}"
                            Text="{Binding Model.ServiceUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" KeyDown="OnEnterKeyDown"
                            Visibility="{Binding Visibility}" />

                    <Button Grid.Row="8" Style="{StaticResource ConfigurationButtonStyle}" Content="Configure" Command="{Binding ConfigureCommand}" />

                    <StackPanel Grid.Row="9">
                        <vuc:ValidationSummary x:Name="validationSummary" VerticalAlignment="Center" HorizontalAlignment="Center" />
                        <TextBlock Style="{StaticResource ErrorTextBlockStyle}" Text="{Binding ErrorMessage}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </StackPanel>
                </Grid>
            </Grid>

            <!--Footer-->
            <ContentControl Grid.Row="2" Template="{StaticResource FooterTemplate}" />
        </Grid>
    </vuc:BusyIndicator>
</visi:VisiPage>
